import * as vscode from 'vscode';
import {authorizationVerification} from "../authorize";

export async function luaGlobalIgnore(context: vscode.ExtensionContext) {
  const isAuthorized = await authorizationVerification(context);
  if (!isAuthorized) {
    return undefined;
  }

  const config = vscode.workspace.getConfiguration('Lua');
  const ignoreGlobals = vscode.workspace.getConfiguration('luaGlobalIgnore').get<string[]>('ignoreGlobals') || [];

  const globals = [
    "GUI",
    "SL"
  ];
  ignoreGlobals.forEach(global => {
    if (!globals.includes(global)) {
      globals.push(global);
    }
  });
  config.update('diagnostics.globals', globals, vscode.ConfigurationTarget.Workspace);

}
